<template>
	<view class="webview-container">
		<status-bar></status-bar>
		<!-- 顶部导航栏 -->
		<view class="nav-bar">
			<view class="nav-back" @click="goBack">
				<text class="iconfont icon-back">&lt;</text>
			</view>
			<view class="nav-title">{{ pageTitle }}</view>
		</view>

		<!-- 网页内容 -->
		<!-- <web-view :src="pageUrl" @message="handleMessage"></web-view> -->
	</view>
</template>

<script>
	export default {
		data() {
			return {
				pageTitle: '',
				pageUrl: '',
				webTop: 0
			}
		},
		onLoad(options) {
			// 获取页面参数
			if (options.title) {
				this.pageTitle = decodeURIComponent(options.title);
			}
			if (options.url) {
				this.pageUrl = decodeURIComponent(options.url);
			}
		},
		mounted() {
			const webTop = uni.upx2px(getApp().globalData.statusBarHeight + 90)
			const webStyle = {
				top: webTop + 'px'
			}
			var w = plus.webview.create(this.pageUrl, 'id', webStyle)
			var currentWebview = this.$mp.page.$getAppWebview()
			currentWebview.append(w)
		},
		methods: {
			goBack() {
				uni.navigateBack();
			},
			handleMessage(event) {
				console.log('来自网页的消息:', event.detail);

			}

		}
	}
</script>

<style lang="scss" scoped>
	.webview-container {
		display: flex;
		flex-direction: column;
		height: 100vh;
	}

	/* 顶部导航栏 */
	.nav-bar {
		display: flex;
		align-items: center;
		height: 90rpx;
		background-color: #4c9bfb;
		color: #fff;
		padding: 0 30rpx;
		position: relative;
	}

	.nav-back {
		position: absolute;
		left: 30rpx;
		font-size: 40rpx;
	}

	.nav-title {
		flex: 1;
		text-align: center;
		font-size: 36rpx;
		white-space: nowrap;
		overflow: hidden;
		text-overflow: ellipsis;
		padding: 0 80rpx;
	}

</style>